5 Lecture

CS401

Midterm & Final Term Short Notes

Program Flow

Program flow refers to the order in which a program executes its instructions or statements. It determines how the program will execute and when specific actions will occur. Control structures, such as conditionals and loops, allow developers to


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. Which of the following control structures is used to execute a block of code repeatedly until a specific condition is met? A) if-else statement B) switch statement C) for loop D) while loop Answer: D) while loop Which of the following statements is used to transfer control to a different part of the program? A) if statement B) switch statement C) break statement D) continue statement Answer: C) break statement Which of the following control structures is used to execute a block of code repeatedly for a specific number of times? A) if-else statement B) switch statement C) for loop D) while loop Answer: C) for loop Which of the following control structures is used to execute a block of code based on the evaluation of a Boolean expression? A) if-else statement B) switch statement C) for loop D) while loop Answer: A) if-else statement Which of the following statements is used to terminate the current iteration of a loop and continue with the next iteration? A) if statement B) switch statement C) break statement D) continue statement Answer: D) continue statement Which of the following statements is used to define a default case in a switch statement? A) default: B) else: C) case default: D) case else: Answer: A) default: Which of the following control structures is used to execute a block of code only if a specific condition is true? A) if-else statement B) switch statement C) for loop D) while loop Answer: A) if-else statement Which of the following statements is used to exit a loop when a specific condition is met? A) if statement B) switch statement C) break statement D) continue statement Answer: C) break statement Which of the following control structures is used to execute a block of code repeatedly as long as a specific condition is true? A) if-else statement B) switch statement C) for loop D) while loop Answer: D) while loop Which of the following statements is used to transfer control to a different part of the program based on a specific condition? A) if statement B) switch statement C) break statement D) goto statement Answer: D) goto statement (Note: goto statement is generally discouraged in modern programming due to its potential to cause confusion and make code harder to read and maintain.)



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is program flow, and why is it important in programming? Answer: Program flow refers to the order in which a program executes its statements or instructions. It is important in programming because it allows developers to control the execution of a program and determine which statements are executed under different conditions. What are control structures in programming, and how do they affect program flow? Answer: Control structures are programming constructs that allow developers to control the flow of a program. They affect program flow by allowing developers to execute certain statements or instructions only under specific conditions. What is the difference between a for loop and a while loop, and when should each be used? Answer: A for loop is used when a specific number of iterations is known in advance, while a while loop is used when the number of iterations is not known in advance. A for loop is usually used when iterating over a collection of items, while a while loop is used when iterating until a certain condition is met. What is a conditional statement in programming, and how is it used to control program flow? Answer: A conditional statement is a programming construct that executes a block of code if a specific condition is met. It is used to control program flow by allowing developers to execute different blocks of code depending on the result of the condition. What is a switch statement in programming, and how is it used to control program flow? Answer: A switch statement is a programming construct that allows developers to execute different blocks of code based on the value of a variable or expression. It is used to control program flow by allowing developers to execute different blocks of code depending on the value of the variable or expression. What is a loop in programming, and how is it used to control program flow? Answer: A loop is a programming construct that allows developers to execute a block of code repeatedly until a specific condition is met. It is used to control program flow by allowing developers to execute the same block of code multiple times under different conditions. What is an if-else statement in programming, and how is it used to control program flow? Answer: An if-else statement is a programming construct that executes one block of code if a specific condition is met and another block of code if the condition is not met. It is used to control program flow by allowing developers to execute different blocks of code depending on the result of the condition. What is a break statement in programming, and how is it used to control program flow? Answer: A break statement is a programming construct that allows developers to terminate the current loop or switch statement and transfer control to a different part of the program. It is used to control program flow by allowing developers to exit a loop or switch statement early if a specific condition is met. What is a continue statement in programming, and how is it used to control program flow? Answer: A continue statement is a programming construct that allows developers to skip the current iteration of a loop and continue with the next iteration. It is used to control program flow by allowing developers to bypass specific iterations of a loop if a specific condition is met. What is a goto statement in programming, and why is it generally discouraged in modern programming? Answer: A goto statement is a programming construct that allows developers to transfer control to a different part of the program based on a specific condition. It is generally discouraged in modern programming because it can make code harder to read and maintain by creating non-linear program flow and potentially leading to unintended consequences.

program flow refers to the order in which a program executes its statements or instructions. In programming, developers use control structures to control the flow of a program. Control structures are constructs that allow developers to execute specific statements or instructions based on specific conditions. The most common control structures used in programming are loops, conditional statements, and switch statements. Loops are used to repeat a set of instructions or statements multiple times. There are several types of loops available in programming, including for loops, while loops, and do-while loops. For loops are used when a specific number of iterations is known in advance, while while loops are used when the number of iterations is not known in advance. Do-while loops are similar to while loops, but they always execute at least once. Conditional statements are used to execute specific statements or instructions based on specific conditions. The most common conditional statement used in programming is the if-else statement. An if-else statement allows developers to execute one block of code if a specific condition is met and another block of code if the condition is not met. Other conditional statements, such as the if statement and the switch statement, are also available in programming. Switch statements are used to execute specific statements or instructions based on the value of a variable or expression. A switch statement contains a set of case statements, each of which corresponds to a specific value of the variable or expression. When the variable or expression matches one of the case statements, the corresponding block of code is executed. Control structures such as loops, conditional statements, and switch statements allow developers to control the flow of a program and determine which statements are executed under different conditions. However, it is important to use control structures carefully and to ensure that program flow remains logical and easy to understand. Overuse of control structures or misuse of control structures can lead to code that is difficult to read, understand, and maintain.